package com.uphone.kingmall.activity.personal.set;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.china.zhuoyue.R;
import com.uphone.kingmall.base.BaseActivity;
import com.uphone.kingmall.main.MainActivity;
import com.uphone.kingmall.utils.ActivityCollector;
import com.uphone.kingmall.utils.CommonUtil;
import com.uphone.kingmall.utils.GlideUtils;
import com.uphone.kingmall.utils.SharedPreferencesHelper;
import com.uphone.kingmall.view.dialog.OnDialogViewClickListener;
import com.uphone.kingmall.view.dialog.RadishDialog;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * <pre>
 *     author : 王雨
 *     e-mail : sunzengyan@outlook.com
 *     time   : 2018/07/31
 *     desc   :设置
 *     version: 1.0
 * </pre>
 */
public class SettingActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.iv_icon)
    ImageView ivIcon;
    @BindView(R.id.rl_personal_set)
    RelativeLayout rlPersonalSet;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.rl_change_phone)
    RelativeLayout rlChangePhone;
    @BindView(R.id.rl_address)
    RelativeLayout rlAddress;
    @BindView(R.id.rl_bind_account)
    RelativeLayout rlBindAccount;
    @BindView(R.id.rl_bind_bank)
    RelativeLayout rlBindBank;
    @BindView(R.id.rl_login_pwd)
    RelativeLayout rlLoginPwd;
    @BindView(R.id.rl_pay_set)
    RelativeLayout rlPaySet;
    @BindView(R.id.rl_tongyong)
    RelativeLayout rlTongyong;
    @BindView(R.id.rl_about_app)
    RelativeLayout rlAboutApp;
    @BindView(R.id.btn_exit)
    Button btnExit;

    @Override
    public int getLayoutContentId() {
        return R.layout.kingmall_activity_setting;
    }

    @Override
    public void initView() {
        setStatusBar();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (!TextUtils.isEmpty(SharedPreferencesHelper.getUserPhone())) {
            tvPhone.setText(SharedPreferencesHelper.getUserPhone() + "");
        }
        if (!TextUtils.isEmpty(SharedPreferencesHelper.getUserImg())) {
            GlideUtils.getInstance().loadCircleImage(this, SharedPreferencesHelper.getUserImg(), ivIcon);
        }
    }

    @Override
    public void initData() {
    }


    @OnClick({R.id.iv_back, R.id.rl_personal_set, R.id.rl_change_phone, R.id.rl_address, R.id.rl_bind_account, R.id.rl_bind_bank, R.id.rl_login_pwd, R.id.rl_pay_set, R.id.rl_tongyong, R.id.rl_about_app, R.id.btn_exit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                onBackPressed();
                break;
            case R.id.rl_personal_set://修改个人资料
                openActivity(PersonalDataActivity.class);
                break;
            case R.id.rl_change_phone://更换手机号
                openActivity(ChangePhoneActivity.class);
                break;
            case R.id.rl_address://我的收货地址
                openActivity(AddressListActivity.class);
                break;
            case R.id.rl_bind_account://绑定社交账号
                openActivity(BindAccountActivity.class);
                break;
            case R.id.rl_bind_bank://绑定银行卡
                openActivity(MyBankListActivity.class);
                break;
            case R.id.rl_login_pwd://修改登录密码
                openActivity(ModifyLoginPwdActivty.class);
                break;
            case R.id.rl_pay_set://支付设置
//                openActivity(ModifyPayPwdActivty.class);
                openActivity(PayPwdManagerActivity.class);
                break;
            case R.id.rl_tongyong://通用
                openActivity(TongYongActivity.class);
                break;
            case R.id.rl_about_app://关于王者商城
                openActivity(AboutAppActivity.class);
                break;
            case R.id.btn_exit:
                exitAlter();
                break;
        }
    }

    private void exitAlter() {
        new RadishDialog.Builder(this).setView(R.layout.kingmall_dialog_alter)
                .setText(R.id.dialog_message, "确定退出？")
                .setClick(R.id.dialog_submit, new OnDialogViewClickListener() {
                    @Override
                    public void onClick(final RadishDialog dialog, View view) {
                        dialog.dismiss();
                        SharedPreferencesHelper.clearTokenAndUserId();
//                        BaseActivity mainActivity = ActivityCollector.getActivity(MainActivity.class);
//                        if (mainActivity != null && mainActivity instanceof MainActivity) {
//                            ((MainActivity) mainActivity).backHome();
//                        }
//                        ActivityCollector.removeAll(MainActivity.class);
                        ActivityCollector.removeAll();
                        CommonUtil.startIntent(SettingActivity.this,MainActivity.class);
                    }
                })
                .setClick(R.id.dialog_cancel, new OnDialogViewClickListener() {
                    @Override
                    public void onClick(RadishDialog dialog, View view) {
                        dialog.dismiss();
                    }
                }).show();
    }
}
